//
//  ZJKWelcomeViewController.swift
//  MicroBlog
//
//  Created by VAD on 16/4/19.
//  Copyright © 2016年 朱江坤. All rights reserved.
//

import UIKit
import SDWebImage

class ZJKWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    
    private func setupUI(){
        
        view.backgroundColor = UIColor(white: 247/255.0, alpha: 1)
        
        view.addSubview(headImage)
        view.addSubview(messageLabel)
        
        headImage.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 80, height: 80))
            make.centerX.equalTo(view)
            make.top.equalTo(200)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImage)
            make.top.equalTo(headImage.snp_bottom).offset(15)
        }
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        headImage.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(100)
        }
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(1, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        print("动画执行完毕,切换根控制器")
                        
                        NSNotificationCenter.defaultCenter().postNotificationName(ZJKChangeRootVCNotification, object: self)
                })
        }
    }


    private lazy var headImage: UIImageView = {
        let imageView = UIImageView(image: UIImage(named:"avatar_default_big" ))
        
        imageView.layer.cornerRadius = 40
        
        imageView.layer.masksToBounds = true
        
        if let avatarImage = ZJKUserAccountViewModel.sharedViewModel.account?.avatar_large{
            imageView.sd_setImageWithURL(NSURL(string: avatarImage), placeholderImage: UIImage(named: "avatar_default_big"))
        }
        
        return imageView
        
    }()
    
    private lazy var messageLabel: UILabel = {
        let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 15)
        label.text = "欢迎回来"
        label.alpha = 0
        return label
    }()


}
